﻿using System;
using System.Configuration;

using Rarous.TexyNet.Parser.Formatter;
using Rarous.TexyNet.Providers;

namespace Rarous.TexyNet.Parser {
  public class IronTexy: ITexyProvider {
    #region Fields
    private ITexyFormatter<String> _formatter;
    private ITexyParser _parser;
    private ITexySettings _settings; 
    #endregion

    #region Constructors
    public IronTexy() {
      _formatter = new XhtmlFormatter();
      _parser = new TexyParser();
    } 
    #endregion

    #region Properties
    public ITexyFormatter<String> Formatter {
      get {
        return _formatter;
      }
      set {
        _formatter = value;
      }
    }

    public ITexyParser Parser {
      get {
        return _parser;
      }
      set {
        _parser = value;
      }
    }

    public string Version {
      get {
        return "IronTexy 1.0";
      }
    }

    public ITexySettings Settings {
      get {
        return _settings;
      }
      set {
        _settings = value;
      }
    } 
    #endregion

    #region Public Methods
    public string Process(string input) {
      Parser.Parse(input);
      Formatter.Root = Parser.Root;
      return Formatter.Format();
    }

    public string Process(string text, ITexySettings settings) {
      Settings = settings;
      return Process(text);
    } 
    #endregion
  }
}